var wineApp = wineApp || {};
wineApp.localStorage = (function() {
    return {
        get: function(key) {
            var value = null;
            try {
                value = $.localStorage.get(key);
            } catch (err) {}
            return value;
        },
        /**
         * [设置本地存储，如果是 key存储的对象是array，在原有的基础上，在把value设置进去，
         *     如果长度超过limit限制，则去掉后面removeCount个数]
         * @param {[type]} key         [description]
         * @param {[type]} value       [description]
         * @param {[type]} limit       [数组的最大长度]
         * @param {[type]} removeCount [要移除的个数]
         */
        set: function(key, value, force, limit, removeCount) {
            var obj = wineApp.localStorage.get(key);
            if (force) {
                $.localStorage.set(key, value);
                return;
            }
            if ($.isArray(obj)) {
                limit = limit == null ? Number.MAX_VALUE : limit;
                removeCount = removeCount == null ? 3 : removeCount;
                if (obj.length > limit) {
                    obj.splice((obj.length - 1 - removeCount), removeCount);
                }
                $.each(value, function(index, val) {
                    obj.splice(0, 0, val);
                });
                $.localStorage.set(key, obj);
            } else {
                $.localStorage.set(key, value);
            }
        },
        remove: function(key) {
            $.localStorage.remove(key);
        }
    }
})()